package com.igoal.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.igoal.entity.Category;

@Repository("categoryDAO")
public class CategoryDAOImpl extends GenericDaoHibernate<Category, Long>
		implements CategoryDAO {

	public CategoryDAOImpl() {
		super(Category.class);
	}

	public Category findByCategory(String category) {
		DetachedCriteria dc = DetachedCriteria.forClass(Category.class);
		dc.add(Restrictions.eq("category", category));
		
		List<Category> result = findByCriteria(dc);
		if(result.size() > 0){
			if(result.size() > 1){
				log.info("Category name is not unique: " + category);
			}
			return result.get(0);
		}
		
		return null;
	}
}
